'use strict';

const Controller = require('egg').Controller;

class UserController extends Controller {

  
    async userLogin(ctx) {

        let u_id = ctx.request.body.u_id
        let nickName = ctx.request.body.nickName
        let avatar = ctx.request.body.avatar
        let sex = ctx.request.body.sex
        var login = await ctx.service.user.userLogin(u_id, nickName, avatar, sex)
        ctx.body = login
    }



    async addRank(ctx) {
        let uid = ctx.query.uid
        let score = ctx.query.score
        let type = ctx.query.type
        var information = await ctx.service.user.addRank(uid, score,type)
        ctx.body = information
    }




    async addFeedBack(ctx) {
        let text = ctx.request.body.text
        let username = ctx.request.body.username
        let avatar = ctx.request.body.avatar
        let u_id = ctx.request.body.u_id
        
        var addFeed = await ctx.service.user.addFeedBack(text, username, avatar, u_id)
        ctx.body = addFeed
    }


    async getQuestionData(ctx) {
        let type = ctx.query.type
        let score = ctx.query.score
        var addFeed = await ctx.service.user.getQuestionData(type, score)
        ctx.body = addFeed
    }


 async getQuestionType(ctx) {
        var information = await ctx.service.user.getQuestionType()
        ctx.body = information
    }

async getQuestion(ctx) {
       let type = ctx.query.type
        var information = await ctx.service.user.getQuestion(type)
        ctx.body = information
    }

     async getHistory(ctx) {
        let uid = ctx.query.uid
        var information = await ctx.service.user.getHistory(uid)
        ctx.body = information
    }






    async getRank(ctx) {
        let type = ctx.query.type
        let start = ctx.query.start
        var information = await ctx.service.user.getRank(type, start)
        ctx.body = information
    }


 async addPraise(ctx) {
        let uid = ctx.query.uid
        let id = ctx.query.id
        var information = await ctx.service.user.addPraise(uid, id)
        ctx.body = information
    }


  async getQuestion(ctx) {
       let type = ctx.query.type
        var information = await ctx.service.user.getQuestion(type)
        ctx.body = information
    }


    async getUserInfo(ctx) {
        let id = ctx.query.id
        var information = await ctx.service.user.getUserInfo(id)
        ctx.body = information
    }

async userAuthLogin(ctx) {
        let code = ctx.query.code
        var login = await ctx.service.user.userAuthLogin(code)
        ctx.body = login
    }


}

module.exports =  UserController
